import 'dart:convert';
import 'package:dio/dio.dart';

const baseUrl = 'http://192.168.13.1:7001';
const contentTypeMap = {
  'application/x-www-form-urlencoded': Headers.formUrlEncodedContentType,
  'application/json': Headers.jsonContentType
};

Future<Map> dioPost(String url,
    {Map data = const {},
    String contentType = 'application/json',
    Map hearders = const {}}) async {
  Dio dio = new Dio();
  if (hearders.isEmpty == false) {
    dio.options.headers = hearders;
  }
  dio.options.contentType = contentTypeMap[contentType.toString()];
  Response res = await dio.post(
    baseUrl + url,
    data: data,
  );
  return json.decode(res.toString());
}

Future<Map> dioGet(String url,
    {String contentType = 'application/json', Map hearders = const {}}) async {
  Dio dio = new Dio();
  if (hearders.isEmpty == false) {
    dio.options.headers = hearders;
  }
  dio.options.contentType = contentTypeMap[contentType.toString()];
  Response res = await dio.get(
    baseUrl + url,
  );
  return json.decode(res.toString());
}
